
#ifndef _HTTP_CLIENT_WRAPPER_
#define _HTTP_CLIENT_WRAPPER_

#ifdef __cplusplus
extern "C" {
#endif

#define  __HARMONY_OS__
#ifdef _WIN32
/*********** Microsoft Windows Support **************/
#pragma warning (disable: 4996) // 'function': was declared deprecated (VS 2005)
#include	<stdlib.h>
#include	<string.h>
#include	<memory.h>
#include	<stdio.h>
#include	<ctype.h>
#include	<time.h>
#include	<winsock.h>

// Sockets (Winsock wrapper)
#define		HTTP_ECONNRESET     (WSAECONNRESET)
#define		HTTP_EINPROGRESS    (WSAEINPROGRESS)
#define		HTTP_EWOULDBLOCK    (WSAEWOULDBLOCK)

// Kluge alert: redefining strncasecmp() as memicmp() for Windows.
//
#define		strncasecmp			memicmp
#define		strcasecmp			stricmp

#else // Non Win32 : GCC Linux
#include	<unistd.h>
#include	<errno.h>
#include	<pthread.h>
#include	<stdlib.h>
#include	<stdio.h>
#include	<string.h>
#include	<ctype.h>
#include	<time.h>
#include	<sys/socket.h>
#include	<sys/un.h>

#if defined(__HARMONY_OS__)
#define _HARMONY_OS_PORTING_
#define UNUSED(var) do { (void)var; } while(0)

//#include	<linux/in.h>
////#include	<netinet/tcp.h>
#include	<lwip/netdb.h>
#include    <lwip/opt.h>
#include	<lwip/sockets.h>
#define accept(a,b,c)         lwip_accept(a,b,c)
#define bind(a,b,c)           lwip_bind(a,b,c)
#define shutdown(a,b)         lwip_shutdown(a,b)
#define closesocket(s)        lwip_close(s)
#define connect(a,b,c)        lwip_connect(a,b,c)
#define getsockname(a,b,c)    lwip_getsockname(a,b,c)
#define getpeername(a,b,c)    lwip_getpeername(a,b,c)
#define setsockopt(a,b,c,d,e) lwip_setsockopt(a,b,c,d,e)
#define getsockopt(a,b,c,d,e) lwip_getsockopt(a,b,c,d,e)
#define listen(a,b)           lwip_listen(a,b)
#define recv(a,b,c,d)         lwip_recv(a,b,c,d)
#define recvfrom(a,b,c,d,e,f) lwip_recvfrom(a,b,c,d,e,f)
#define send(a,b,c,d)         lwip_send(a,b,c,d)
#define sendto(a,b,c,d,e,f)   lwip_sendto(a,b,c,d,e,f)
#define socket(a,b,c)         lwip_socket(a,b,c)
#define select(a,b,c,d,e)     lwip_select(a,b,c,d,e)
#define ioctlsocket(a,b,c)    lwip_ioctl(a,b,c)

#define read(a,b,c)           lwip_read(a,b,c)
#define write(a,b,c)          lwip_write(a,b,c)
#define close(s)              lwip_close(s)
#define fcntl(a,b,c)          lwip_fcntl(a,b,c)
#else
#include	<netinet/in.h>
#include	<netinet/tcp.h>
#include	<netdb.h>
#endif

#include	<arpa/inet.h>
#include	<sys/ioctl.h>
#include	<errno.h>
#include	<stdarg.h>

#define		SOCKET_ERROR      -1
#define		HTTP_EINPROGRESS  (EINPROGRESS)
#define		HTTP_EWOULDBLOCK  (EWOULDBLOCK)
#endif	// #ifdef _WIN32

// STDC Wrapper implimentation
int HTTPWrapperIsAscii     (int c);
int HTTPWrapperToUpper(int c);
int HTTPWrapperToLower(int c);
int HTTPWrapperIsAlpha(int c);
int HTTPWrapperIsAlNum(int c);
char* HTTPWrapperItoa(char *buff,int i);
void HTTPWrapperInitRandomeNumber(void);
long HTTPWrapperGetUpTime(void);
int HTTPWrapperGetRandomeNumber(void);
int HTTPWrapperGetSocketError       (int s);
unsigned long HTTPWrapperGetHostByName        (char *name,unsigned long *address);
int HTTPWrapperShutDown(int s,int in);

// SSL Wrapper prototypes
int HTTPWrapperSSLConnect(long *s,const struct sockaddr_in *name,int namelen,char *hostname);
int HTTPWrapperSSLNegotiate(long s,const struct sockaddr *name,int namelen,char *hostname);
int HTTPWrapperSSLSend(long s, unsigned char *buf, int len,int flags);
int HTTPWrapperSSLRecv(long s, unsigned char *buf, int len,int flags);
int HTTPWrapperSSLClose(long s);
int HTTPWrapperSSLRecvPending       (long s);

// Global wrapper Functions
#define IToA               HTTPWrapperItoa
#define GetUpTime          HTTPWrapperGetUpTime
#define SocketGetErr       HTTPWrapperGetSocketError
#define HostByName         HTTPWrapperGetHostByName
#define InitRandomeNumber  HTTPWrapperInitRandomeNumber
#define GetRandomeNumber   HTTPWrapperGetRandomeNumber

// Global socket structures and definitions
#define                    HTTP_INVALID_SOCKET (-1)
typedef struct sockaddr_in HTTP_SOCKADDR_IN;
typedef struct timeval     HTTP_TIMEVAL;
typedef struct hostent     HTTP_HOSTNET;
typedef struct sockaddr    HTTP_SOCKADDR;
typedef struct in_addr     HTTP_INADDR;

#ifdef __cplusplus
}
#endif

#endif // _HTTP_CLIENT_WRAPPER_
